package com.kws.system.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kws.common.core.utils.StringUtils;
import com.kws.system.domain.info.QueryChatReplyInfo;
import com.kws.system.domain.info.QueryCustomerServiceConsultInfo;
import com.kws.system.domain.vo.QueryCustomerServiceConsultRq;
import com.kws.system.mapper.CustomerServiceConsultMapper;
import com.kws.system.service.CustomerServiceConsultService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * <b>CustomerServiceConsultServiceImpl</b>
 *
 * @description: CustomerServiceConsultServiceImpl <br>
 * @date: 2024/12/6 11:21 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class CustomerServiceConsultServiceImpl implements CustomerServiceConsultService {
    private static final Logger logger = LoggerFactory.getLogger(CustomerServiceConsultServiceImpl.class);

    @Autowired
    private CustomerServiceConsultMapper customerServiceConsultMapper;

    @Override
    public Page<QueryCustomerServiceConsultInfo> queryCustomerServiceConsultPage(QueryCustomerServiceConsultRq rq) {

        List<QueryCustomerServiceConsultInfo> resultList = customerServiceConsultMapper.queryCustomerServiceConsultPage(rq);
        if (CollectionUtil.isNotEmpty(resultList)){
            Page<QueryCustomerServiceConsultInfo> page = new Page<>(rq.getPageNum(), rq.getPageSize());
            Page<QueryCustomerServiceConsultInfo> pageInfo = customerServiceConsultMapper.queryCustomerServiceConsult(page,resultList,rq);
            return pageInfo;
        }
        return null;
    }

    public static void main(String[] args) {
        List<QueryCustomerServiceConsultInfo> list = new ArrayList<>();
        QueryCustomerServiceConsultInfo queryCustomerServiceConsultInfo = new QueryCustomerServiceConsultInfo();
        queryCustomerServiceConsultInfo.setSendUser(1l);
        queryCustomerServiceConsultInfo.setToUser(330l);
        list.add(queryCustomerServiceConsultInfo);
        QueryCustomerServiceConsultInfo queryCustomerServiceConsultInfo1 = new QueryCustomerServiceConsultInfo();
        queryCustomerServiceConsultInfo1.setSendUser(330l);
        queryCustomerServiceConsultInfo1.setToUser(1l);
        list.add(queryCustomerServiceConsultInfo1);
        List<QueryCustomerServiceConsultInfo> distinctList = list.stream()
                .filter(a -> list.stream()
                        .anyMatch(b -> a.getSendUser() == b.getToUser()))
                .collect(Collectors.toList());

        distinctList.forEach(item -> {
            System.out.println(item.getSendUser()+"----"+item.getToUser());
        });
    }

    @Override
    public Page<QueryChatReplyInfo> queryChatReplyList(Integer pageNum, Integer pageSize) {
        Page<QueryChatReplyInfo> page = new Page<>(pageNum, pageSize);
        Page<QueryChatReplyInfo> pageInfo = customerServiceConsultMapper.queryChatReplyList(page);
        return pageInfo;
    }
}
